#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
#include<algorithm>

int n, p, ret = -1;
const int N = 1e6 + 10;
int arr[N];

int main()
{
    cin >> n >> p;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    sort(arr, arr + n);
    int left = 0, right = 0;
    p *= 2;
    while (right < n)
    {
        while (arr[right] - arr[left] > p)
        {
            left++;
        }
        if (right - left + 1 > ret)
            ret = right - left + 1;
        right++;
    }
    cout << ret << endl;
    return 0;
}